package com.swt.testdemo.util;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.util.Date;

/**
 * JSON时间格式序列化
 *
 * @author BleethNie
 * @version 1.0
 * @date 2020-01-08 16:12
 **/
public class JsonDateDeserialize extends JsonDeserializer<Date> {

    @Override
    public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
        String dateAsString = jp.getText();
        Date parseDate;
        parseDate = DateUtil.parse(dateAsString);
        return parseDate;
    }
}